//
// Created by xqyr on 2025/3/30.
//

#include "fservice.h"
#include "ftype.h"
FService::FService(const char *name, CBaseWorker *worker)
: CBaseServer(name, worker) {
    FDB_LOG_D("FService::FServi\n");
}

void FService::onOnline(FdbSessionId_t sid, bool is_first) {
    FDB_LOG_D("onOnline sid=%d, is_first=%d\n", sid, is_first);
}

void FService::onOffline(FdbSessionId_t sid, bool is_last) {
    FDB_LOG_D("onOffline sid=%d, is_last=%d\n", sid, is_last);
}

void FService::onBroadcast(CBaseJob::Ptr &msg_ref) {
    FDB_LOG_D("onBroadcast %xd\n",msg_ref.get());
}

void FService::onInvoke(CBaseJob::Ptr &msg_ref) {
    FDB_LOG_D("onInvoke %xd \n",msg_ref.get());
}

void FService::onSubscribe(CBaseJob::Ptr &msg_ref){
   // FDB_LOG_D("onSubscribe\n");
    auto msg = castToMessage<CFdbMessage *>(msg_ref);
    const CFdbMsgSubscribeItem *sub_item;
    FDB_BEGIN_FOREACH_SIGNAL(msg, sub_item)
     {
         FDB_LOG_D("onSubscribe sub_item code=%xd,filter=%s\n",sub_item->msg_code(),sub_item->filter().c_str());
         CFdbProtoMsgBuilder builder();
         msg->broadcast(sub_item->msg_code());
     }
    FDB_END_FOREACH_SIGNAL()
}
